package com.jic.member.controller.power;


import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.MememberIntegralOrderRecharge;
import com.jic.member.request.power.MememberIntegralOrderRechargeRequest;
import com.jic.member.service.MememberIntegralOrderRechargeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: ymh
 * @date: 2020-01-09
 * @remark: 会员积分下单-充值赠送controller
 */

@ApiOperation(value = "会员积分下单-充值赠送controller")
@RestController
@RequestMapping("/integralOrderRecharge")
@Slf4j
public class MemberIntegralOrderRechargeController {

    @Autowired
    MememberIntegralOrderRechargeService mememberIntegralOrderRechargeService;

    /*
     * 会员等级权益查询
     * */
    @ApiOperation(value = "根据Id获取会员会员积分下单/充值赠送规则")
    @ResponseBody
    @RequestMapping("/queryIntegralOrderInfoById")
    public RestResult queryIntegralOrderRechargeInfo(@RequestBody MememberIntegralOrderRechargeRequest form) {
        log.info("开始进入获取会员会员积分下单/充值赠送规则=========》,{}", form.toString());
        MememberIntegralOrderRecharge  result = mememberIntegralOrderRechargeService.queryByPrimaryKey(form.getId());
        return RestResult.success(result);
    }


    /**
     * 编辑会员积分下单/充值赠送规则
     * @param form
     * @return
     */
    @ApiOperation(value="编辑会员积分下单/充值赠送规则", notes="编辑会员积分下单/充值赠送规则")
    @ResponseBody
    @RequestMapping("/editMemberInfo")
    public RestResult<String> editMemberInfo(@RequestBody MememberIntegralOrderRechargeRequest form) {
        log.info("开始进入会员积分下单/充值赠送规则=========》,{}", form.toString());
        RestResult restResult = new RestResult<>();
        try {
            MememberIntegralOrderRecharge memberRequest = BeanUtil.copy(form, MememberIntegralOrderRecharge.class);
            mememberIntegralOrderRechargeService.update(memberRequest);
            restResult=RestResult.success("编辑成功");
        } catch (Exception e) {
            log.error("error",e);
            restResult=RestResult.error("9999",e.getLocalizedMessage());
        }
        return restResult;
    }

}
